package tchk.xyz.lingyuntutorminiprogram.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tchk.xyz.lingyuntutorminiprogram.dto.LoginDTO;
import tchk.xyz.lingyuntutorminiprogram.dto.WxLoginResponseDTO; // 新增
import tchk.xyz.lingyuntutorminiprogram.service.IUserService;
import tchk.xyz.lingyuntutorminiprogram.utils.Result;

@RestController
@RequestMapping("/api/auth")
public class AuthController {

    @Autowired
    private IUserService userService;

    /**
     * [新增] 小程序微信登录接口
     */
    @PostMapping("/wx-login")
    public Result<WxLoginResponseDTO> wxLogin(@RequestBody LoginDTO loginDTO) {
        // 我们把业务逻辑都封装到Service层
        WxLoginResponseDTO response = userService.wxLogin(loginDTO.getCode());
        return Result.success(response);
    }

    /**
     * 后台管理员登录接口
     */
    @PostMapping("/admin/login")
    public Result<String> adminLogin(@RequestBody LoginDTO loginDTO) {
        String token = userService.adminLogin(loginDTO);
        return Result.success(token);
    }
}